function checkMyNum() {
    debug && console.info("WANote: Checking myprofile...");
    try {
        var a = document.getElementsByClassName("pane-list-user");
        if (a.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        var b = a[0].getElementsByClassName("icon-user-default");
        if (b.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        var c = b[0].getElementsByClassName("avatar-body");
        if (c.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        var d = c[0].getElementsByTagName("img"),
            e = d[0].src,
            f = e.substr(e.indexOf("&u=") + 3);
        if (f = f.substr(0, f.indexOf("%40")), f.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        chrome.runtime.sendMessage({
                from: "content",
                subject: "avatar",
                avatar: e,
                number: f
            }),
            toDataURL(e,
                function(a) {
                    chrome.runtime.sendMessage({
                        from: "content",
                        subject: "avatar",
                        avatar: a
                    })
                })
    } catch (g) {
        console.error("WANote: Exception while checking avatar"),
            console.error(g)
    }
}

function toDataURL(a, b, c) {
    var d = new Image;
    d.crossOrigin = "Anonymous",
        d.onload = function() {
            var a, d = document.createElement("CANVAS"),
                e = d.getContext("2d");
            d.height = this.height,
                d.width = this.width,
                e.drawImage(this, 0, 0),
                a = d.toDataURL(c),
                b(a)
        },
        d.src = a,
        (d.complete || void 0 === d.complete) && (d.src = "", d.src = a)
}

function sendPush() {
    sendbutton = document.getElementsByClassName("_2lkdt"),
        1 == sendbutton.length ? sendbutton[0].click() : window.setTimeout(sendPush, 1e3)
}

function getMensajes() {
    var a = JSON.parse(JSON.stringify(Store.Chat))[0].msgs,
        b = [];
    if (a.length > 0)
        for (i = 0; i < a.length; i++) {
            var c = a[i].body;
            b.push(c)
        }
    return b
}

function sendNewMsg() {
    var a = document.getElementById("phonetosend").value;
    a = a.replace("+", "");
    var b = document.getElementById("messagetosend").value;
    "" == b && (b = WhatsDockLink),
        wdlauncher("openchatat", {
            id: a,
            msg: b
        }),
        numbers = a.split(",");
    var c = numbers.length,
        d = c;
    for (c >= 25 && (c = 25), i = 0; i < c; i++) a = numbers[i],
        trackSendEvent(),
        wdStats({
            number: a,
            message: b,
            event: "whatsdockmsg"
        });
    sendingmessage = !1,
        c < 25 && document.getElementsByClassName("PhoneClass")[0].remove(),
        checknumberofrecipients(d)
}

function getMyNum() {
    var a = document.getElementsByClassName("pane-list-user");
    if (a.length < 1) return "";
    var b = a[0].getElementsByClassName("avatar");
    if (b.length < 1) return "";
    var c = b[0].getElementsByTagName("img");
    if (c.length < 1) return "";
    var d = c[0].src,
        e = d.substr(d.indexOf("&u=") + 3);
    return e = e.substr(0, e.indexOf("%40"))
}

function savemynumandmyavatar() {
    try {
        var a = document.getElementsByClassName("pane-list-user");
        if (a.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        var b = a[0].getElementsByClassName("avatar");
        if (b.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        var c = b[0].getElementsByTagName("img"),
            d = c[0].src,
            e = d.substr(d.indexOf("&u=") + 3);
        if (e = e.substr(0, e.indexOf("%40")), e.length < 1) return void window.setTimeout(checkMyNum, 1e3);
        oldmynum === e && oldmyavatar === d || (oldmyavatar = d, oldmynum = e, chrome.runtime.sendMessage({
            from: "content",
            subject: "avatar",
            avatar: d,
            number: e
        }), toDataURL(d,
            function(a) {
                chrome.runtime.sendMessage({
                    from: "content",
                    subject: "avatar",
                    avatar: a
                })
            }))
    } catch (f) {}
}

function showphoneinfo() {
    var a = document.getElementById("infophone");
    a.style.width = "100%"
}

function getFilteredContacts(a) {
    if (0 == a.length || "#FFFFFF" == a[0]) {
        var b = document.querySelector("#wdcontactspanel");
        if (null !== b) {
            b.remove();
            var c = document.querySelector("div[wacontactslistpanel]");
            null !== c && (c.style.display = "block")
        }
        var d = document.getElementById("phonetosend");
        null !== d && (d.value = getMyNum()),
            document.querySelector("#messagetosend").setAttribute("placeholder", chrome.i18n.getMessage("newchatphonelabel"))
    } else {
        var e = JSON.parse(localStorage.wdcolor),
            f = {};
        for (var g in e) {
            var h = e[g];
            for (i = 0; i < a.length; i++) h == a[i] && (f[g] = {})
        }
        wdlauncher("getfilteredcontactsinfo", {
            contacts: f
        })
    }
}

function filterContacts(a) {
    var b = JSON.parse(localStorage.wdcolor),
        c = document.querySelector("div[wacontactslistpanel]");
    if (null !== c) {
        var d = document.querySelector("#wdcontactspanel");
        null !== d && (d.remove(), c.style.display = "block");
        var d = document.createElement("div");
        d.id = "wdcontactspanel";
        var e = document.getElementById("phonetosend"),
            f = "";
        for (var g in a) {
            g.indexOf("@c.us") >= 0 && ("" !== f && (f += ",+"), f += g.replace("@c.us", ""));
            var h = document.createElement("div");
            h.style.backgroundColor = hexToRgbA(b[g]),
                h.className = "chat chatfilter",
                h.setAttribute("wacontactid", g);
            var j = document.createElement("div");
            j.className = "chat-avatar";
            var k = document.createElement("div");
            k.className = "avatar",
                k.style.width = "49px",
                k.style.height = "49px";
            var l = document.createElement("img");
            l.setAttribute("src", a[g].picture),
                l.style.width = "49px",
                l.style.height = "49px",
                k.appendChild(l),
                j.appendChild(k);
            var m = document.createElement("div");
            m.className = "chat-body";
            var n = document.createElement("div");
            n.className = "chat-main";
            var o = document.createElement("span");
            o.innerHTML = a[g].name,
                n.appendChild(o);
            var p = document.createElement("div");
            p.className = "chat-secondary";
            var q = document.createElement("span");
            q.innerHTML = a[g].msg,
                q.className = "chatfilterspan",
                p.appendChild(q),
                m.appendChild(n),
                m.appendChild(p),
                h.appendChild(j),
                h.appendChild(m),
                d.appendChild(h),
                document.querySelector("#messagetosend").setAttribute("placeholder", chrome.i18n.getMessage("newchatphonelabelcolorfilter"))
        }
        null !== e && (e.value = f),
            c.parentElement.insertBefore(d, c);
        var r = document.querySelectorAll(".chatfilter");
        for (i = 0; i < r.length; i++) r[i].addEventListener("click",
            function(a) {
                a.preventDefault(),
                    a.stopPropagation();
                var b = this.getAttribute("wacontactid");
                wdlauncher("openchatat", {
                    id: b
                })
            });
        null !== document.querySelector("#wdtemplatespanel") && document.querySelector("#wdtemplatespanel").remove(),
            c.style.display = "none"
    }
}

function templatesShow() {
    var a = document.querySelector("div[wacontactslistpanel]");
    if (null !== a) {
        null !== document.querySelector("#wdcontactspanel") && (document.querySelector("#wdcontactspanel").style.display = "none");
        var b = document.querySelector("#wdtemplatespanel");
        null !== b && (b.remove(), b.style.display = "block");
        var b = document.createElement("div");
        b.id = "wdtemplatespanel";
        var c = parseFloat(getComputedStyle(a.parentElement.parentElement.parentElement).height);
        b.style.height = c - 110 + "px";
        var d = document.createElement("span");
        d.className = "wdtemplatestitle",
            d.innerText = chrome.i18n.getMessage("templatestitle"),
            b.appendChild(d);
        var e = document.createElement("div");
        e.className = "wdtemplateclose",
            e.innerText = "x",
            b.appendChild(e);
        var f = 0;
        if ("undefined" != typeof localStorage.wdtemplates) {
            var g = localStorage.wdtemplates,
                h = JSON.parse(g);
            for (i = 0; i < h.length; i++) {
                var j = document.createElement("textarea");
                j.className = "wdtemplatetextarea",
                    j.setAttribute("placeholder", chrome.i18n.getMessage("templatesplaceholder")),
                    j.setAttribute("order", f),
                    j.value = h[i],
                    b.appendChild(j),
                    f += 1
            }
        }
        var j = document.createElement("textarea");
        j.className = "wdtemplatetextarea",
            j.setAttribute("placeholder", chrome.i18n.getMessage("templatesplaceholder")),
            j.setAttribute("order", f),
            b.appendChild(j),
            a.parentElement.parentElement.parentElement.appendChild(b);
        var k = document.querySelectorAll(".wdtemplatetextarea");
        for (i = 0; i < k.length; i++) k[i].addEventListener("mousedown",
                function(a) {
                    a.stopPropagation(),
                        this.setAttribute("active", !0),
                        document.getElementById("messagetosend").value = this.value,
                        null !== document.querySelector(".pluggable-input-compose>.pluggable-input-body") && (document.querySelector(".pluggable-input-compose>.pluggable-input-body").innerText = this.value, null !== document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder") && ("" == this.value ? document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder").style.visibility = "visible" : document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder").style.visibility = "hidden"))
                }),
            k[i].addEventListener("mouseup",
                function(a) {
                    this.focus()
                }),
            k[i].addEventListener("blur",
                function(a) {
                    this.removeAttribute("active"),
                        templatesShow()
                }),
            k[i].addEventListener("keydown",
                function() {
                    templateskeypressdown = !0
                }, !1),
            k[i].addEventListener("keyup",
                function(a) {
                    if (templateskeypressdown === !0) {
                        document.getElementById("messagetosend").value = this.value,
                            null !== document.querySelector(".pluggable-input-compose>.pluggable-input-body") && (document.querySelector(".pluggable-input-compose>.pluggable-input-body").innerText = this.value, null !== document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder") && ("" == this.value ? document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder").style.visibility = "visible" : document.querySelector(".pluggable-input-compose>.pluggable-input-placeholder").style.visibility = "hidden"));
                        var b = [];
                        "undefined" != typeof localStorage.wdtemplates && (b = JSON.parse(localStorage.wdtemplates)),
                            b[this.getAttribute("order")] = this.value,
                            "" == this.value && b.splice(this.getAttribute("order"), 1),
                            localStorage.wdtemplates = JSON.stringify(b),
                            this.style.height = "45px",
                            this.style.height = this.scrollHeight + "px"
                    }
                    templateskeypressdown = !1
                }, !1);
        for (b.addEventListener("mousedown",
                function(a) {
                    a.preventDefault()
                }), i = 0; i < document.querySelectorAll(".wdtemplatetextarea").length; i++) document.querySelectorAll(".wdtemplatetextarea")[i].style.height = "45px",
            document.querySelectorAll(".wdtemplatetextarea")[i].style.height = document.querySelectorAll(".wdtemplatetextarea")[i].scrollHeight + "px";
        e.addEventListener("click",
                function(a) {
                    a.preventDefault(),
                        document.getElementById("messagetosend").focus(),
                        document.getElementById("wdtemplatespanel").remove();
                    var b = document.querySelector("div[wacontactslistpanel]");
                    null !== b && (b.style.display = "block")
                }),
            a.style.display = "none"
    }
}

function htmlcircle(a, b) {
    return "<div style='display:inline-block;position:relative;width:22px;height:22px;'><div class='wdcircle' style='background: " + a + ";border:1px solid " + b + ";' wdcolor='" + a + "'></div><div class='wdoutercircle'></div></div>"
}

function pincircle(a) {
    var b = ".12";
    return a && (b = ".25"),
        '<div style="display:inline-block;position:relative;width:22px;height:22px;cursor:pointer;"><div class="wdcircle" style="margin-top:-2px;margin-left:1px" wdcolor="pin" wdpin=' + a + '><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 19" width="20" height="20"><path fill="#263238" fill-opacity="' + b + '" d="M9.5 18.419C4.574 18.419.581 14.426.581 9.5S4.574.581 9.5.581s8.919 3.993 8.919 8.919-3.993 8.919-8.919 8.919zm2.121-5.708l-.082-2.99 1.647-1.963a1.583 1.583 0 0 0-.188-2.232l-.32-.269a1.58 1.58 0 0 0-2.231.203L8.803 7.42l-2.964.439a.282.282 0 0 0-.14.496l5.458 4.58c.186.157.47.019.464-.224zM5.62 13.994a.504.504 0 0 0 .688-.038l2.204-2.307-1.085-.91-1.889 2.571a.504.504 0 0 0 .082.684z"></path></svg></div><div class="wdoutercircle"></div></div>'
}

function htmlcirclefilter(a, b) {
    var c = "";
    return "#FFFFFF" == a && (c = "+"),
        "<div style='display:inline-block;position:relative;width:20px;height:12px;top:-1px;' data='123'><div class='wdcirclefilter'  style='background: " + a + ";border:1px solid " + b + ";' wdcolor='" + a + "'>" + c + "</div><div class='wdouterfiltercircle'></div></div>"
}

function getContactBGColor(a) {
    var b = new Object;
    return "undefined" != typeof localStorage.wdcolor && (b = JSON.parse(localStorage.wdcolor)),
        "undefined" != typeof b[a.toString()] ? b[a.toString()] : ""
}

function setContactBGColor(a, b) {
    var c = new Object;
    "undefined" != typeof localStorage.wdcolor && (c = JSON.parse(localStorage.wdcolor)),
        "#FFFFFF" == b || "pin" == b ? delete c[a.toString()] : c[a.toString()] = b,
        localStorage.wdcolor = JSON.stringify(c)
}

function getContactNotes(a) {
    var b = new Object;
    return "undefined" != typeof localStorage.wdnotes && (b = JSON.parse(localStorage.wdnotes)),
        "undefined" != typeof b[a.toString()] ? b[a.toString()] : ""
}

function setContactNotes(a, b) {
    var c = new Object;
    "undefined" != typeof localStorage.wdnotes && (c = JSON.parse(localStorage.wdnotes)),
        "" == b ? delete c[a.toString()] : c[a.toString()] = b,
        localStorage.wdnotes = JSON.stringify(c)
}

function hexToRgbA(a) {
    var b;
    if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(a)) return b = a.substring(1).split(""),
        3 == b.length && (b = [b[0], b[0], b[1], b[1], b[2], b[2]]),
        b = "0x" + b.join(""),
        "rgba(" + [b >> 16 & 255, b >> 8 & 255, 255 & b].join(",") + ",0.1)";
    throw new Error("Bad Hex")
}

function isPinned(a) {
    var b = !1;
    return document.querySelectorAll("div:not(.well-chat)[wacontactid='" + a + "']").length > 0 && document.querySelectorAll("div:not(.well-chat)[wacontactid='" + a + "']")[0].querySelectorAll("span[data-icon='pinned']").length > 0 && (b = !0),
        b
}

function injectScript(a, b) {
    var c = document.getElementsByTagName(b)[0],
        d = document.createElement("script");
    d.setAttribute("type", "text/javascript"),
        d.setAttribute("src", a),
        c.appendChild(d)
}

var infoIcon = "data:image/svg+xml;base64, PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHdpZHRoPSIxMzBweCIgaGVpZ2h0PSIxMzBweCIgdmlld0JveD0iMTUgMTUgMTMwIDEzMCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAxNSAxNSAxMzAgMTMwIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxnPg0KCTxwYXRoIGZpbGw9IiM0QjRCNEIiIGQ9Ik04MCwxNWMtMzUuODgsMC02NSwyOS4xMi02NSw2NXMyOS4xMiw2NSw2NSw2NXM2NS0yOS4xMiw2NS02NVMxMTUuODgsMTUsODAsMTV6IE04MCwyNQ0KCQljMzAuMzU5LDAsNTUsMjQuNjQsNTUsNTVjMCwzMC4zNTktMjQuNjQxLDU1LTU1LDU1Yy0zMC4zNiwwLTU1LTI0LjY0MS01NS01NUMyNSw0OS42NCw0OS42NCwyNSw4MCwyNXoiLz4NCgk8cGF0aCBmaWxsPSIjNEI0QjRCIiBkPSJNODkuOTk4LDUxLjI1MWMwLDYuMjEzLTUuMDM2LDExLjI1LTExLjI1LDExLjI1Yy02LjIxMywwLTExLjI1LTUuMDM3LTExLjI1LTExLjI1DQoJCWMwLTYuMjE0LDUuMDM3LTExLjI1LDExLjI1LTExLjI1Qzg0Ljk2Miw0MCw4OS45OTgsNDUuMDM3LDg5Ljk5OCw1MS4yNTF6Ii8+DQoJPHBhdGggZmlsbD0iIzRCNEI0QiIgZD0iTTkwLjY2NSwxMTAuOTZjLTAuMDY5LDIuNzI5LDEuMjExLDMuNSw0LjMyNywzLjgybDUuMDA4LDAuMVYxMjBINjAuOTI3di01LjEybDUuNTAzLTAuMQ0KCQljMy4yOTEtMC4xMDEsNC4wODItMS4zOCw0LjMyNy0zLjgyVjgwLjE0N2MwLjAzNS00Ljg3OS02LjI5Ni00LjExMy0xMC43NTctMy45Njh2LTUuMDc0TDkwLjY2NSw3MCIvPg0KPC9nPg0KPC9zdmc+DQo=",
    phoneButton = "data:image/svg+xml;base64, PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4wLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSLzIwMDEvUkVDLVNWRy0yMDAxMDkwNC9EVEQvc3ZnMTAuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4wIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHdpZHRoPSI3NC4wODlweCIgaGVpZ2h0PSI5OS44MThweCIgdmlld0JveD0iMCAwIDc0LjA4OSA5OS44MTgiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDc0LjA4OSA5OS44MTgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHBhdGggaWQ9InBhdGgzNDgwXzFfIiBkPSJNMjEuNTQ3LDAuMDkxYzAsMC0yMS44MjcsMC4yODctMjEuNTQ0LDIwLjA1OWMwLjI4NCwxOS43NzMsNC4yNTMsMzcuMjU1LDEwLjc3Myw0Ni45OTgNCgljNi41MTksOS43NDQsMjMuMjQyLDM1LjI0OCw0Mi4yMzYsMzIuNjdjMCwwLDkuMzU1LTIuMDA3LDE2LjQ0LTYuNTkzTDQ2LjQ5Miw3NS4xNzFjMCwwLTYuODAzLDQuMjk5LTExLjA1NS0xLjQzMw0KCWMtNC4yNTMtNS43My0xNy41NzUtMzIuMzgxLTE3LjU3NS0zMi4zODFzLTMuNjg1LTguNTk4LDQuNTM2LTEyLjMyM0wyMS41NDcsMC4wOTF6Ii8+DQo8cGF0aCBpZD0icGF0aDM0ODJfMV8iIGQ9Ik0yNC4wOTksMC4wOTFjMCwwLDEuNzAxLTAuNTcxLDQuODE4LDEuMTQ3YzMuMTE4LDEuNzE5LDMuMTE4LDMuMTUsMy4xMTgsMy4xNWwwLjI4NCwxOS43NzUNCgljMCwwLTAuODUxLDEuMTQ3LTEuOTg0LDIuMjkxYy0xLjEzNCwxLjE0Ni00LjgxOSwyLjg2Ny01LjM4NywxLjcyQzI0LjM4MywyNy4wMjksMjQuMDk5LDAuMDkxLDI0LjA5OSwwLjA5MXoiLz4NCjxwYXRoIGlkPSJwYXRoMzQ4NF8xXyIgZD0iTTQ4LjQwMSw3My4wNThsNi4zMTItMy4zMzJjMCwwLDEuNDE3LTAuMjg1LDMuNjg0LDEuMTQ2DQoJYzIuMjY4LDEuNDM2LDE0LjE3NCwxMC44OTMsMTQuMTc0LDEwLjg5M3MxLjk4NCwxLjcxOSwxLjQxNywzLjcyNWMtMC41NjYsMi4wMDYtMS45ODQsNi4zMDUtMS45ODQsNi4zMDVMNDguNDAxLDczLjA1OHoiLz4NCjwvc3ZnPg0K",
    closeIconSrc = "data:image/svg+xml;base64, PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjI0cHgiDQoJIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNCAyNDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGcgaWQ9Ikljb25zIiBzdHlsZT0ib3BhY2l0eTowLjc1OyI+DQoJPGcgaWQ9ImNsb3NlIj4NCgkJPHBvbHlnb24gaWQ9IngiIHN0eWxlPSJmaWxsLXJ1bGU6ZXZlbm9kZDtjbGlwLXJ1bGU6ZXZlbm9kZDsiIHBvaW50cz0iMTguNzE3LDYuNjk3IDE3LjMwMyw1LjI4MyAxMiwxMC41ODYgNi42OTcsNS4yODMNCgkJCTUuMjgzLDYuNjk3IDEwLjU4NiwxMiA1LjI4MywxNy4zMDMgNi42OTcsMTguNzE3IDEyLDEzLjQxNCAxNy4zMDMsMTguNzE3IDE4LjcxNywxNy4zMDMgMTMuNDE0LDEyIAkJIi8+DQoJPC9nPg0KPC9nPg0KPGcgaWQ9Ikd1aWRlcyIgc3R5bGU9ImRpc3BsYXk6bm9uZTsiPg0KPC9nPg0KPC9zdmc+DQo=",
    sendButton = "data:image/svg+xml;base64, PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiPjxwYXRoIG9wYWNpdHk9Ii40IiBkPSJNMS4xMDEgMjEuNzU3TDIzLjggMTIuMDI4IDEuMTAxIDIuM2wuMDExIDcuOTEyIDEzLjYyMyAxLjgxNi0xMy42MjMgMS44MTctLjAxMSA3LjkxMnoiPjwvcGF0aD48L3N2Zz4NCg==",
    WhatsDockLink = "https://chrome.google.com/webstore/detail/whatsdock->-whatsapp-for/mbphanhcahfecdomhgfoclcklneeihcj",
    scriptElem = document.createElement("script");
scriptElem.innerHTML = "window.onbeforeunload = null;";
var lastToolbarIconWarn = -1,
    lastToolbarIconBadgeText = -1,
    lastToolbarIconTooltipText = -1,
    setrate = !1,
    noteskeypressdown = !1,
    templateskeypressdown = !1,
    PanesClass = {};
PanesClass.pane = "pane",
    PanesClass["pane-one"] = "pane-one",
    PanesClass["pane-two"] = "pane-two",
    PanesClass["pane-three"] = "pane-three",
    updatepanes = !0;
var wdlauncher = function(a, b) {
        "undefined" == typeof b && (b = {}),
            b.op = a;
        var c = new CustomEvent("wdlmk", {
            bubbles: !0,
            cancelable: !1,
            detail: b
        });
        document.dispatchEvent(c)
    },
    saverate = function(a) {
        var b = new Date,
            c = b.getFullYear() + ("0" + (b.getMonth() + 1)).slice(-2) + ("0" + b.getDate()).slice(-2) + ("0" + b.getHours()).slice(-2) + ("0" + b.getMinutes()).slice(-2) + ("0" + b.getSeconds()).slice(-2),
            d = getMyNum(),
            e = {
                date: c,
                rate: a,
                id: d
            };
        localStorage.wdrate = JSON.stringify(e),
            chrome.runtime.sendMessage({
                name: "getsetRate",
                setrate: !1
            }),
            sendAppRate(a, d)
    },
    inputsearchphoneshowfunction = function() {
        var a = document.getElementsByClassName("chatlist-panel-body");
        if (a.length > 0) {
            insertphoneinfo(),
                wdlauncher("welcometxt");
            var b = document.getElementsByClassName("PhoneClass");
            b.length > 0 && b[0].remove();
            var c = document.createElement("div");
            c.className = "PhoneClass";
            var d = document.createElement("div");
            d.className = "wdpowered",
                d.innerHTML = "Powered by <a href='" + WhatsDockLink + "' target='_blank'>WhatsDock</a>";
            var e = document.createElement("span");
            e.setAttribute("id", "phonelabel"),
                e.textContent = chrome.i18n.getMessage("newchatphonelabel");
            var f = document.createElement("span");
            f.setAttribute("id", "phonelabelplus"),
                f.textContent = "+";
            var g = document.createElement("span");
            g.className = "phonelabellimit",
                g.innerHTML = chrome.i18n.getMessage("phonelabellimit");
            var h = document.createElement("input");
            h.setAttribute("id", "phonetosend"),
                h.setAttribute("empty", "1"),
                h.setAttribute("type", "text"),
                h.setAttribute("tabindex", "1"),
                h.setAttribute("data-tab", "5"),
                h.setAttribute("placeholder", chrome.i18n.getMessage("newchatphoneholder")),
                h.style.borderStyle = "solid",
                h.value = getMyNum(),
                "" !== h.value && h.removeAttribute("empty");
            var k = document.createElement("img");
            k.setAttribute("id", "phoneinfoicon"),
                k.setAttribute("src", infoIcon);
            var l = document.createElement("img");
            l.setAttribute("id", "phonebutton"),
                l.setAttribute("src", phoneButton);
            var m = document.createElement("img");
            m.setAttribute("id", "closebutton"),
                m.setAttribute("src", closeIconSrc);
            var n = document.createElement("textarea");
            n.setAttribute("id", "messagetosend"),
                n.setAttribute("placeholder", chrome.i18n.getMessage("newchatphonelabel")),
                n.setAttribute("tabindex", "2"),
                n.setAttribute("data-tab", "6");
            var o = document.createElement("div");
            o.className = "wdtemplateopenicon",
                o.innerText = "T";
            var p = document.createElement("img");
            p.setAttribute("id", "sendbutton"),
                p.setAttribute("src", sendButton),
                c.appendChild(d),
                c.appendChild(f),
                c.appendChild(g),
                c.appendChild(h),
                c.appendChild(k),
                c.appendChild(n),
                c.appendChild(o),
                c.appendChild(p);
            var q = setrate;
            if (q && "undefined" == typeof localStorage.wdrate) {
                var r = document.createElement("div");
                r.className = "wdrate";
                var s = document.createElement("div");
                s.className = "wdrateclose",
                    s.innerText = "x";
                var t = document.createElement("div");
                t.className = "wdrateelement";
                var u = document.createElement("div");
                u.className = "wdratelogocontainer";
                var v = document.createElement("div");
                v.className = "wdratelogoholder";
                var w = document.createElement("img");
                w.className = "wdratelogo",
                    w.setAttribute("src", chrome.extension.getURL("img/whatsDock.svg")),
                    v.appendChild(w),
                    u.appendChild(v);
                var x = document.createElement("div");
                x.className = "wdratetextcontainer";
                var y = document.createElement("div");
                y.className = "wdratetextmain";
                var z = document.createElement("div");
                z.className = "wdratetextmaintitle",
                    z.innerText = chrome.i18n.getMessage("reviewtitle"),
                    y.appendChild(z);
                var A = document.createElement("div");
                A.className = "wdratestarsmain";
                var B = document.createElement("div");
                for (B.className = "wdratestars", i = 1; i <= 5; i++) {
                    var C = document.createElement("span");
                    C.className = "wdratestar",
                        B.appendChild(C)
                }
                A.appendChild(B),
                    x.appendChild(y),
                    x.appendChild(A),
                    t.appendChild(u),
                    t.appendChild(x),
                    r.appendChild(s),
                    r.appendChild(t),
                    c.appendChild(r),
                    c.className = "PhoneClass wdrateBlock"
            }
            var D = document.querySelector("." + PanesClass["pane-one"] + " header.pane-header .pane-list-controls");
            var K = document.querySelector("body");

            // // 插入订单查询弹出按钮
            // beforSertTabBtn()

            // //调用layer弹窗组件
            // showLayerWin();
            // showLayerWin2();
            // // labPage();
            // //好友列表绑定点击事件
            // bindFriendClick();
            // //获取当前登录人手机号
            // var phone = "";
            // if ("undefined" != typeof localStorage.waMyNum && "" !== localStorage.waMyNum) {
            //     phone = localStorage.waMyNum;
            //     var str = phone.substring(2); //从第二个字符开始截取
            //     var arr = str.split("@");
            //     var input_phone = "<input id='phone' type='hidden' value='" + arr[0] + "'/>";
            //     $("body").append(input_phone);
            // }
            // // 历史记录功能模块
            // // 调用获取好友列表方法
            //  GETFriends();
            //  ChangeFriend();
            if ("object" == typeof D && null !== D && 0 == document.querySelectorAll(".wdshare").length) {
                //关注 追加爱心
                var E = document.createElement("img");
                //var F = document.createElement("span");
                E.setAttribute("src", chrome.extension.getURL("img/heart.svg")),
                    E.className = "wdshare",
                    //F.className = "span",
                    //F.innerHTML="常用回复",
                    //将新元素插入到目标元素之前
                    D.parentElement.insertBefore(E, D),
                    //D.parentElement.insertBefore(F, D),
                    //调用关注的信息
                    insertshareinfo(),
                    //调用常用语的信息
                    infowin(),
                    //关注(爱心)点击事件
                    E.addEventListener("click",
                        function(a) {
                            a.preventDefault(),
                                a.stopPropagation();
                            var b = document.getElementById("wdshare");
                            b.style.width = "100%"
                        });


            }


            var F = a[0];
            if (F.insertBefore(c, F.childNodes[0]), o.addEventListener("click",
                    function(a) {
                        a.preventDefault(),
                            templatesShow()
                    }), n.addEventListener("mousedown",
                    function(a) {
                        document.getElementById("messagetosend").setAttribute("active", !0),
                            window.setTimeout(function() {
                                    document.getElementById("messagetosend").focus()
                                },
                                200)
                    }), h.addEventListener("mousedown",
                    function(a) {
                        document.getElementById("phonetosend").setAttribute("active", !0),
                            window.setTimeout(function() {
                                    document.getElementById("phonetosend").focus()
                                },
                                200)
                    }), n.addEventListener("focus",
                    function(a) {
                        a.preventDefault(),
                            document.getElementById("messagetosend").setAttribute("active", !0)
                    }), n.addEventListener("blur",
                    function(a) {
                        a.preventDefault(),
                            document.getElementById("messagetosend").removeAttribute("active")
                    }), h.addEventListener("blur",
                    function(a) {
                        a.preventDefault(),
                            document.getElementById("phonetosend").removeAttribute("active")
                    }), h.addEventListener("focus",
                    function(a) {
                        a.preventDefault(),
                            document.getElementById("phonetosend").setAttribute("active", !0)
                    }), m.addEventListener("click",
                    function(a) {
                        document.getElementsByClassName("PhoneClass")[0].remove()
                    }), k.addEventListener("click",
                    function(a) {
                        a.preventDefault(),
                            showphoneinfo()
                    }), q && "undefined" == typeof localStorage.wdrate) {
                var G = document.querySelectorAll(".wdratestar");
                for (j = 0; j < G.length; j++) G[j].addEventListener("mouseover",
                    function(a) {
                        a.preventDefault(),
                            a.stopPropagation();
                        var b = document.querySelectorAll(".wdratestar"),
                            c = 0;
                        for (i = 0; i < b.length; i++) b[i] === this && (c = i);
                        for (i = 0; i < b.length; i++) b[i].className = "wdratestar",
                            i <= c && (b[i].className += " on")
                    });
                for (j = 0; j < G.length; j++) G[j].addEventListener("click",
                    function(a) {
                        a.preventDefault(),
                            a.stopPropagation();
                        var b = document.querySelectorAll(".wdratestar"),
                            c = 0;
                        for (i = 0; i < b.length; i++) b[i] === this && (c = i, saverate(i + 1));
                        c >= 3 && window.open("https://chrome.google.com/webstore/detail/whatsdock->-whatsapp-for/mbphanhcahfecdomhgfoclcklneeihcj/reviews", "_blank");
                        var d = document.querySelectorAll(".wdrate");
                        d.length > 0 && d[0].remove();
                        var d = document.querySelectorAll(".PhoneClass");
                        d.length > 0 && (d[0].className = "PhoneClass")
                    });
                r.addEventListener("mouseover",
                        function(a) {
                            a.preventDefault(),
                                a.stopPropagation();
                            var b = document.querySelectorAll(".wdratestar");
                            for (i = 0; i < b.length; i++) b[i].className = "wdratestar"
                        }),
                    s.addEventListener("click",
                        function(a) {
                            var b = document.querySelectorAll(".wdrate");
                            b.length > 0 && b[0].remove(),
                                saverate(0);
                            var b = document.querySelectorAll(".PhoneClass");
                            b.length > 0 && (b[0].className = "PhoneClass")
                        })
            }
            p.addEventListener("click",
                    function(a) {
                        sendingmessage = !0,
                            sendNewMsg()
                    }),
                h.addEventListener("keypress",
                    function(a) {
                        return 43 == a.which || 44 == a.which || !(a.which < 48 || a.which > 57) || (a.preventDefault(), !1)
                    }, !1),
                n.addEventListener("keyup",
                    function(a) {
                        this.value.length > 0 ? (document.getElementById("sendbutton").style.width = "100%", document.getElementById("sendbutton").style.opacity = "1", this.style.width = parseFloat(getComputedStyle(document.getElementById("phonetosend")).width) - 30 + "px", document.querySelector(".wdtemplateopenicon").className = "wdtemplateopenicon typing") : (document.getElementById("sendbutton").style.width = "0%", document.getElementById("sendbutton").style.opacity = "0", this.style.width = getComputedStyle(document.getElementById("phonetosend")).width, document.querySelector(".wdtemplateopenicon").className = "wdtemplateopenicon")
                    })
        }
    },
    checknumberofrecipients = function(a) {
        var b = document.getElementById("phonetosend");
        return "undefined" == typeof a && (a = b.value.split(",").length),
            a >= 25 ? (document.getElementById("sendbutton").style.width = "0%", document.getElementById("sendbutton").style.opacity = "0", document.getElementById("messagetosend").style.width = getComputedStyle(document.getElementById("phonetosend")).width, document.getElementById("messagetosend").value = "", document.getElementById("messagetosend").style.display = "none", document.getElementsByClassName("phonelabellimit")[0].style.display = "block", document.querySelector(".wdtemplateopenicon").className = "wdtemplateopenicon", !1) : (document.getElementById("messagetosend").style.display = "inline-block", document.getElementsByClassName("phonelabellimit")[0].style.display = "none", !0)
    },
    inputsearchphonehidefunction = function() {
        var a = document.getElementsByClassName("PhoneClass");
        a.length > 0 && window.setTimeout(function() {
                if (document.getElementsByClassName("list-search") && document.getElementsByClassName("list-search")[0].className.indexOf("active") == -1 && (!document.getElementById("messagetosend") || !document.getElementById("messagetosend").hasAttribute("active"))) {
                    var a = document.getElementsByClassName("PhoneClass");
                    a.length > 0 && (a[0].style.display = "none", sendingmessage || a[0].remove()),
                        setsearcheventfocus = !1
                }
            },
            500)
    },
    insertphoneinfo = function() {
        // whatsapp版本升级后修改
        // if (null === document.getElementById("infophone")) {
        //     var a = generateInsertPhone(),
        //     b = document.createElement("div");
        //     b.innerHTML = a,
        //     document.getElementsByClassName(PanesClass["pane-one"])[0].appendChild(b),
        //     document.getElementById("infophone").getElementsByClassName("drawer-title-action")[0].addEventListener("click",
        //     function() {
        //         document.getElementById("infophone").style.width = "0%"
        //     })
        // }
    },
    generateInsertPhone = function() {
        var a = '<div id="infophone" style="top: 0px; left: 0px; z-index: 13000;height: 100%; opacity: 1; background-color: #3D3E3E; transition: width 0.3s; width:0; border: 0px; position: absolute"><div class="drawer drawer-notifications" style="transform: translateX(0px);overflow:scroll;"><header class="drawer-header" style="height: 59px"> <div class="pane-header drawer-title" style="padding: 0px; background-color: transparent;"> <div class="drawer-title-action" style="text-align: initial; width: 54px;"> <span data-icon="back-light" class=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="#FFF" d="M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20v-2z"></path></svg></span></div><span class="drawer-title-body" style="font-weight: 500; font-size: 19px; line-height: normal;">' + chrome.i18n.getMessage("phoneinfo") + '</span> </div> </header> <div class="drawer-body drawer-body-wide" style="padding-bottom: 20px;"> <div class="controls-container drawer-section" style="padding-left:25px;"> <div class="controls-section" style="padding:0 0 10px 0;"> <div class="label">' + chrome.i18n.getMessage("phoneinfo_title1") + '<div class="hint" style="padding-top:5px;">' + chrome.i18n.getMessage("phoneinfo_title1_text1") + '</div><br/> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text2") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text3") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text4") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text5") + '</div><br/> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text6") + '</div><br/> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title1_text7") + '</div><br/> <div class="hint" style="color:#ff0000;">' + chrome.i18n.getMessage("phoneinfo_title1_text8") + '</div> </div> </div> <div class="controls-section" style="padding:10px 0;"> <div class="label">' + chrome.i18n.getMessage("phoneinfo_title2") + '<div class="hint" style="padding-top:5px;">' + chrome.i18n.getMessage("phoneinfo_title2_text1") + '</div><br/> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title2_text2") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title2_text3") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title2_text4") + '</div> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title2_text5") + '</div></div> </div> <div class="controls-section" style="padding:10px 0;"> <div class="label">' + chrome.i18n.getMessage("phoneinfo_title3") + '<div class="hint" style="padding-top:5px;">' + chrome.i18n.getMessage("phoneinfo_title3_text1") + '</div><br/> <div class="hint">' + chrome.i18n.getMessage("phoneinfo_title3_text2") + "</div> </div> </div> </div> </div> </div></div>";
        return a
    },
    insertshareinfo = function() {
        if (null === document.getElementById("wdshare")) {
            var a = generateWDShare(),
                b = document.createElement("div");
            b.innerHTML = a,
                document.getElementsByClassName(PanesClass["pane-one"])[0].appendChild(b),
                document.getElementById("wdshare").getElementsByClassName("drawer-title-action")[0].addEventListener("click",
                    function() {
                        document.getElementById("wdshare").style.width = "0%"
                    })
        }
    },
    generateWDShare = function() {
        var a = '<div id="wdshare" style="top: 0px; left: 0px; z-index: 13000;height: 100%; opacity: 1; background-color: #3D3E3E; transition: width 0.3s; width:0; border: 0px; position: absolute"><div class="drawer drawer-notifications" style="transform: translateX(0px);overflow:scroll;"><header class="drawer-header" style="height: 59px"> <div class="pane-header drawer-title" style="padding: 0px; background-color: transparent;"> <div class="drawer-title-action" style="text-align: initial; width: 54px;"> <span data-icon="back-light" class=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="#FFF" d="M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20v-2z"></path></svg></span></div><span class="drawer-title-body" style="font-weight: 500; font-size: 19px; line-height: normal;">' + chrome.i18n.getMessage("sharetitle") + '</span> </div> </header> <div class="drawer-body drawer-body-wide" style="padding-bottom: 20px;"> <div class="controls-container drawer-section" style="padding-left:25px;"> <div class="controls-section" style="padding:0 0 10px 0;"> <div class="label">' + chrome.i18n.getMessage("sharetitlemsg") + '<div class="hint" style="padding-top:15px;"><img src="' + chrome.extension.getURL("img/ico_mail.svg") + '" width="20" height="20" style="vertical-align:middle;padding-right:5px;"/>' + chrome.i18n.getMessage("share_email") + '</div><div class="hint" style="padding-top:15px;"><img src="' + chrome.extension.getURL("img/ico_twitter.svg") + '" width="20" height="20" style="vertical-align:middle;padding-right:5px;"/>' + chrome.i18n.getMessage("share_twitter") + '</div> <div class="hint" style="padding-top:15px;"><img src="' + chrome.extension.getURL("img/ico_facebook.svg") + '" width="20" height="20" style="vertical-align:middle;padding-right:5px;"/>' + chrome.i18n.getMessage("share_facebook") + '</div> <br><div class="hint" style="padding-top:15px;">' + chrome.i18n.getMessage("suggestions") + "</div></div> </div> </div> </div> </div></div>";
        return a
    },


    infowin = function() {
        if (null === document.getElementById("wdshare2")) {
            var a = generateWDShare2(),
                b = document.createElement("div");
            b.innerHTML = a,
                document.getElementsByClassName(PanesClass["pane-one"])[0].appendChild(b),
                document.getElementById("wdshare2").getElementsByClassName("drawer-title-action2")[0].addEventListener("click",
                    function() {
                        document.getElementById("wdshare2").style.width = "0%"
                    })
        }
    },
    generateWDShare2 = function() {
        var a = '<div id="wdshare2" style="top: 0px; left: 0px; z-index: 13000;height: 100%; opacity: 1; background-color: #3D3E3E; transition: width 0.3s; width:0; border: 0px; position: absolute">' +
            '<div class="drawer drawer-notifications" style="transform: translateX(0px);overflow:scroll;">' +
            '<header class="drawer-header" style="height: 59px">' +
            '<div class="pane-header drawer-title" style="padding: 0px; background-color: transparent;"> ' +
            '<div class="drawer-title-action2" style="text-align: initial; width: 54px;"> ' +
            '<span data-icon="back-light" class="">' +
            '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">' +
            '<path fill="#FFF" d="M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20v-2z"></path>' +
            '</svg>' +
            '</span>' +
            '</div>' +
            '<span class="drawer-title-body" style="font-weight: 500; font-size: 19px; line-height: normal;">常用回复</span>' +
            '</div>' +
            '</header> ' +
            '<div class="drawer-body drawer-body-wide" style="padding-bottom: 20px;"> ' +
            '<div class="controls-container drawer-section" style="padding-left:25px;"> ' +
            '<div class="controls-section" style="padding:0 0 10px 0;"> ' +
            '</div>' +
            ' </div>' +
            '</div>';
        return a
    },
    insertFilterPanel = function() {
        // var a = document.querySelector(".chatlist-panel-search");
        // if (null !== a) {
        //     a.childNodes[0].className.indexOf("list-search") == -1 && (document.styleSheets[0].addRule("." + document.querySelector(".chatlist-panel-search").childNodes[0].className + ":after", "border-bottom: 0px!important;"), a.childNodes[0].className += " list-search");
        //     var b = document.querySelector(".wdfilter");
        // if (null === b) {
        //     var b = document.createElement("div");
        //     b.className = "wdfilter";
        //     var c = document.createElement("span");
        //     //追加圆点 htmlcirclefilter
        //     c.innerHTML = "<span>" + chrome.i18n.getMessage("filtertag") + ":</span>" + htmlcirclefilter("#FE625C", "#FF3A30") + htmlcirclefilter("#F9A646", "#F69418") + htmlcirclefilter("#6DCC50", "#4FC129") + htmlcirclefilter("#4BB8F3", "#16A7F1"),
        //         b.appendChild(c),
        //         a.appendChild(b)
        // }
        // for (var d = 0; d < b.getElementsByClassName("wdcirclefilter").length; d++) b.getElementsByClassName("wdcirclefilter")[d].addEventListener("click",
        //     function(a) {
        // a.preventDefault(),
        //     a.stopPropagation();
        // var b = !1;
        // "#FFFFFF" == this.getAttribute("wdcolor") && (b = !0),
        //     "wdcirclefilter" != this.className || b ? this.className = "wdcirclefilter" : this.className = "wdcirclefilter on",
        //     circlesfilterel = document.querySelectorAll(".wdcirclefilter.on");
        // var c = [];
        // for (j = 0; j < circlesfilterel.length; j++) b ? circlesfilterel[j].className = "wdcirclefilter" : c.push(circlesfilterel[j].getAttribute("wdcolor"));
        // b && c.push("#FFFFFF"),
        //             //     getFilteredContacts(c)
        //         })
        // }

        // // 历史记录功能模块
        // 调用获取好友列表方法
        // GETFriends();
        // ChangeFriend();
    },
    inyectcontactpanel = function() {
        var a = document.getElementsByClassName("well-chat"),
            b = document.querySelector(".pluggable-input-compose");
        if (null !== b && null == document.querySelector(".wdtemplateopeniconinput")) {
            var c = document.createElement("div");
            c.className = "wdtemplateopeniconinput",
                c.innerText = "T",
                b.appendChild(c),
                c.addEventListener("click",
                    function(a) {
                        a.preventDefault(),
                            templatesShow()
                    })
        }
        if (a.length > 0) {
            a = a[0],
                currentwaid = a.getAttribute("wacontactid"),
                wdlauncher("chatContacts", {
                    waid: currentwaid
                }),
                currentwaid.indexOf("@c.us") > 0 && (a.nextSibling.nextSibling.style.paddingLeft = "10px", a.nextSibling.nextSibling.style.display = "inline-block", a.childNodes[0].style.width = "100px", a.childNodes[0].style.height = "100px", a.childNodes[0].style.marginTop = "10px"),
                currentwaid = a.getAttribute("wacontactid"),
                null !== document.getElementById("wdcolorpanel") && document.getElementById("wdcolorpanel").remove();
            var d = document.createElement("div");
            d.setAttribute("id", "wdcolorpanel");
            d.innerHTML = "<div class='wdcircletag'><span>Tags:</span> " + htmlcircle("#FE625C", "#FF3A30") + htmlcircle("#F9A646", "#F69418") + htmlcircle("#6DCC50", "#4FC129") + htmlcircle("#4BB8F3", "#16A7F1") + htmlcircle("#FFFFFF", "#EEEEEE") + "&nbsp;&nbsp;&nbsp;" + pincircle(!0) + "</div>",
                a.insertBefore(d, a.childNodes[0]),
                null !== document.getElementById("wdnotespanel") && document.getElementById("wdnotespanel").remove();
            var e = document.createElement("div");
            e.setAttribute("id", "wdnotespanel");
            var f = document.createElement("textarea");
            f.setAttribute("id", "wdnotes"),
                f.setAttribute("placeholder", chrome.i18n.getMessage("notes_placeholder")),
                "" !== getContactNotes(currentwaid) && (f.value = getContactNotes(currentwaid)),
                f.setAttribute("contactid", currentwaid),
                e.appendChild(f),
                a.parentElement.appendChild(e),
                f.style.height = "45px",
                f.style.height = f.scrollHeight + "px",
                wdlauncher("detailblockclass");
            var g = document.querySelector("." + PanesClass["pane-three"] + " .btn-close-drawer");
            null !== g && null === g.getAttribute("active") && (g.addEventListener("click",
                function(a) {
                    localStorage.wdpanelclose = !0
                }), g.setAttribute("active", !0));
            var h = document.querySelector("." + PanesClass["pane-three"] + " .wdpowered");
            if (null == h && "object" == typeof h) {
                var h = document.querySelector("." + PanesClass["pane-three"] + " header");
                if (null !== h && "object" == typeof h) {
                    var i = document.createElement("div");
                    i.className = "wdpowered",
                        i.innerHTML = "Powered by <a href='" + WhatsDockLink + "' target='_blank'>WhatsDock</a>",
                        h.appendChild(i)
                }
            }
            for (var k = 0; k < a.getElementsByClassName("wdcircle").length; k++) a.getElementsByClassName("wdcircle")[k].addEventListener("click",
                function(b) {
                    if (b.preventDefault(), currentwaid = a.getAttribute("wacontactid"), "#FFFFFF" == this.getAttribute("wdcolor")) {
                        if (document.getElementsByClassName("well-chat")[0].parentElement.style.background = "#FFFFFF", cleanelement = document.querySelectorAll('div.infinite-list-item-transition[wacontactid="' + currentwaid + '"]'), cleanelement.length > 0)
                            for (k = 0; k < cleanelement.length; k++) cleanelement[k].querySelectorAll(".chat")[0].style.background = "inherit"
                    } else "pin" == this.getAttribute("wdcolor") ? document.getElementsByClassName("well-chat")[0].setAttribute("setpin", !isPinned(currentwaid)) : (document.getElementsByClassName("well-chat")[0].parentElement.style.background = hexToRgbA(this.getAttribute("wdcolor")), document.getElementsByClassName("well-chat")[0].style.background = "transparent");
                    setContactBGColor(currentwaid, this.getAttribute("wdcolor")),
                        colorcontacts();
                    var c = [];
                    for (j = 0; j < circlesfilterel.length; j++) c.push(circlesfilterel[j].getAttribute("wdcolor"));
                    getFilteredContacts(c),
                        "pin" !== this.getAttribute("wdcolor") && wdContactChange({
                            contact: currentwaid,
                            color: this.getAttribute("wdcolor")
                        })
                });
            return f.addEventListener("keydown",
                    function() {
                        noteskeypressdown = !0
                    }, !1),
                f.addEventListener("keyup",
                    function() {
                        noteskeypressdown === !0 && (setContactNotes(this.getAttribute("contactid"), this.value), this.style.height = "45px", this.style.height = this.scrollHeight + "px"),
                            noteskeypressdown = !1
                    }, !1),
                f.addEventListener("blur",
                    function() {
                        wdContactChange({
                            contact: this.getAttribute("contactid"),
                            notes: this.value
                        })
                    }, !1),
                null !== currentwaid ? "" !== getContactBGColor(currentwaid) && "undefined" != typeof getContactBGColor(currentwaid) && (document.getElementsByClassName("well-chat")[0].parentElement.style.background = hexToRgbA(getContactBGColor(currentwaid)), document.getElementsByClassName("well-chat")[0].style.background = "transparent") : window.setTimeout(function() {
                        currentwaid = document.getElementsByClassName("well-chat")[0].getAttribute("wacontactid"),
                            "" !== getContactBGColor(currentwaid) && "undefined" != typeof getContactBGColor(currentwaid) && (document.getElementsByClassName("well-chat")[0].parentElement.style.background = hexToRgbA(getContactBGColor(currentwaid)), document.getElementsByClassName("well-chat")[0].style.background = "transparent")
                    },
                    1e3),
                colorcontacts(), !0
        }
        return colorcontacts(), !1
    },
    injectCalendarSharePanel = function(a, b) {
        var c = document.createElement("div");
        c.setAttribute("id", "wdCalendarShare"),
            c.className = a;
        var d = document.createElement("div");
        d.className = b;
        var e = document.createElement("span");
        e.style.color = "#128C7E",
            e.style.fontSize = "14px",
            e.style.fontWeight = "300",
            e.style.lineHeight = "normal",
            e.innerText = chrome.i18n.getMessage("create_event"),
            d.appendChild(e);
        var f = document.createElement("div");
        f.className = b;
        var g = document.createElement("span"),
            h = "",
            i = document.querySelectorAll(".wdName");
        i.length > 0 && (h = i[0].innerText);
        var j = "",
            k = document.querySelectorAll(".wdNumber");
        k.length > 0 && (j = k[0].innerText);
        var l = (new Date).toISOString().replace(/-/g, "").replace(/:/g, "").replace(/\./g, ""),
            m = "<a href='https://calendar.google.com/calendar/render?action=TEMPLATE&text=" + encodeURI(h) + "+++" + encodeURI(j).replace("+", "%2B") + "' target='_blank'><img src='" + chrome.extension.getURL("img/google.svg") + "'/> Google</a>";
        m += "<a href='http://calendar.live.com/calendar/calendar.aspx?rru=addevent&summary=" + encodeURI(h) + "+++" + encodeURI(j).replace("+", "%2B") + "' target='_blank'><img src='" + chrome.extension.getURL("img/outlook.svg") + "' style='padding-left:20px;'/> Outlook</a>",
            m += "<a href='https://calendar.yahoo.com/?v=60&view=d&type=20&title=" + encodeURI(h) + "+++" + encodeURI(j).replace("+", "%2B") + "&st=" + l + "&dur=&desc=&in_loc=' target='_blank'><img src='" + chrome.extension.getURL("img/yahoo.svg") + "' style='padding-left:20px;'/> Yahoo</a>",
            g.innerHTML = m,
            f.appendChild(g),
            c.appendChild(d),
            c.appendChild(f);
        var n = document.getElementsByClassName("well-chat");
        n.length > 0 && n[0].parentNode.parentNode.insertBefore(c, n[0].parentNode.nextSibling),
            document.getElementById("messagetosend").value.length > 0 ? (document.getElementById("sendbutton").style.width = "100%", document.getElementById("sendbutton").style.opacity = "1", document.getElementById("messagetosend").style.width = parseFloat(getComputedStyle(document.getElementById("phonetosend")).width) - 30 + "px", document.querySelector(".wdtemplateopenicon").className = "wdtemplateopenicon typing") : (document.getElementById("sendbutton").style.width = "0%", document.getElementById("sendbutton").style.opacity = "0", document.getElementById("messagetosend").style.width = getComputedStyle(document.getElementById("phonetosend")).width, document.querySelector(".wdtemplateopenicon").className = "wdtemplateopenicon")
    },
    colorcontacts = function(a) {
        a = "undefined" == typeof a ? "" : '[wastate="' + a + '"]';
        var b = document.querySelectorAll("div[wacontactid]:not(.well-chat)" + a);
        if (b.length > 0)
            for (b[0].parentElement.hasAttribute("wacontactslistpanel") || "wdcontactspanel" === b[0].parentElement.getAttribute("id") || b[0].parentElement.setAttribute("wacontactslistpanel", ""), i = 0; i < b.length; i++) b[i].querySelectorAll("div.chat.active").length > 0 ? b[i].style.borderLeft = "6px solid #bdbdbd" : b[i].style.borderLeft = "inherit",
                null !== b[i].getAttribute("wacontactid") && "" !== getContactBGColor(b[i].getAttribute("wacontactid")) ? b[i].querySelectorAll(".chat").length > 0 && (b[i].querySelectorAll(".chat")[0].style.background = hexToRgbA(getContactBGColor(b[i].getAttribute("wacontactid")))) : b[i].querySelectorAll(".chat").length > 0 && (b[i].querySelectorAll(".chat")[0].style.background = "inherit"),
                "" !== a && b[i].removeAttribute("wastate")
    };
document.addEventListener("wdIay",
    function(a) {
        if ("web.whatsapp.com" == a.srcElement.domain)
            if ("welcomedone" == a.detail.op) {
                document.getElementsByClassName(a.detail["class"]).length > 0 && (document.getElementsByClassName(a.detail["class"])[0].innerHTML = chrome.i18n.getMessage("intromsg"));
                var b = document.querySelector("div[data-asset-intro-image]");
                "object" == typeof b && chrome.runtime.sendMessage({
                    name: "setopenindock"
                })
            } else if ("refreshcontacts" == a.detail.op) colorcontacts();
        else if ("idexistsdone" == a.detail.op) chrome.runtime.sendMessage({
            name: "getcontactexistsdone",
            id: a.detail.id,
            exists: a.detail.exists,
            tabid: a.detail.tabid
        });
        else if ("needcolorpanel" == a.detail.op) inyectcontactpanel();
        else if ("gotDetailBlockClass" == a.detail.op) injectCalendarSharePanel(a.detail.container, a.detail.title);
        else if ("gotPanesBlockClass" == a.detail.op) updatepanes = !1,
            PanesClass.pane = a.detail.pane,
            PanesClass["pane-one"] = a.detail.paneone,
            PanesClass["pane-two"] = a.detail.panetwo,
            PanesClass["pane-three"] = a.detail.panethree;
        else if ("gotFilteredData" == a.detail.op) filterContacts(a.detail.contacts);
        else if ("chatOpened" == a.detail.op) {
            var c = document.querySelector(".pluggable-input-body");
            null !== c && sendPush()
        } else if ("insertContactsList" == a.detail.op) {
            var d = document.getElementById("phonetosend"),
                e = "";
            if (null !== d) {
                for (i = 0; i < a.detail.contacts.length; i++) i > 0 && (e += ",+"),
                    e += a.detail.contacts[i].replace("@c.us", "");
                d.value = e,
                    a.detail.contacts.length > 1 ? document.querySelector("#messagetosend").setAttribute("placeholder", chrome.i18n.getMessage("newchatphonelabelgroup")) : document.querySelector("#messagetosend").setAttribute("placeholder", chrome.i18n.getMessage("newchatphonelabel"))
            }
        } else if ("endMessageSend" == a.detail.op) {
            var f = [];
            for (circlesfilterel = document.querySelectorAll(".wdcirclefilter.on"), j = 0; j < circlesfilterel.length; j++) f.push(circlesfilterel[j].getAttribute("wdcolor"));
            f.legth > 0 && getFilteredContacts(f)
        }
    });
var preloadtaggedcontacts = function() {
    // var a = JSON.parse(localStorage.wdcolor),
    //     b = {};
    // for (var c in a) {
    //     a[c];
    //     b[c] = {}
    // }
    // wdlauncher("getfilteredcontactsinfo", {
    //     contacts: b,
    //     dontsendback: !0
    // })
};
chrome.runtime.onMessage.addListener(function(a, b, c) {
        if ("undefined" != typeof a.getRate) setrate = "true" === a.getRate || 1 == a.getRate;
        else if ("undefined" != typeof a.changewelcolmelogo) {
            var d = document.querySelector("div[data-asset-intro-image]");
            null !== d && "object" == typeof d && (d.style.backgroundImage = "url('" + chrome.extension.getURL("img/welcome_dock.png") + "')", d.style.lineHeight = parseFloat(getComputedStyle(d).height) - 20 + "px", d.style.display = "table", d.style.cursor = "pointer", d.style.fontSize = "72%", d.innerHTML = "<span style='display:table-cell;vertical-align:middle;'>" + chrome.i18n.getMessage("welcome_dock") + "</span>", d.addEventListener("click",
                function(a) {
                    chrome.runtime.sendMessage({
                        name: "openindock"
                    })
                }))
        }
    }),
    chrome.runtime.sendMessage({
        name: "getsetRate"
    });
var hasClass = (function() {
    var div = document.createElement("div");
    if ("classList" in div && typeof div.classList.contains === "function") {
        return function(elem, className) {
            return elem.classList.contains(className);
        };
    } else {
        return function(elem, className) {
            var classes = elem.className.split(/\s+/);
            for (var i = 0; i < classes.length; i++) {
                if (classes[i] === className) {
                    return true;
                }
            }
            return false;
        };
    }
})();




// 获取好友列表
function GETFriends() {
    var ket = $("._25Ooe");
    // console.log(ket)
    var arruserId = [];
    for (var i = 0; i < ket.length; i++) {
        var userId = ket[i].innerText;
        if ("+".indexOf(userId) > 0) {
            userId = userId.split("+");
            userId = userId[1];
        }
        userId = userId.replace(/[^0-9]+/g, '');
        // userId = userId.split("@");
        // userId = userId[0];
        // userId = userId.substring(2)
        arruserId.push(userId);

        // console.log(userId)
    }
    // console.log(arruserId)

}

function ChatHistory() {
    var arrObj = [];
    // 一 、聊天记录中接收的信息内容
    // 1、获取对应好友的聊天记录接收内容
    var chat = $(".message-in span.invisible-space");
    var arrChat = [];
    for (var i = 0; i < chat.length; i++) {
        var chatOne = chat[i].innerText;
        arrChat.push(chatOne);
        // console.log(chatOne)
    }
    arrChat = arrChat.splice(-10, 10)
    // 2、获取聊天记录接收的时间与账号名
    var chattimes = $(".message-in div.copyable-text");
    // console.log(chattimes)
    var arrtimes = [];
    var FriendPhone = "";
    for (var i = 0; i < chattimes.length; i++) {
        var chattime = chattimes[i].getAttribute("data-pre-plain-text");
        if (chattime != "" && chattime != null) {
            chattime = chattime.split("]");
            FriendPhone = chattime[1];
            if (FriendPhone.indexOf('+') != -1) {
                FriendPhone = FriendPhone.split("+");
                FriendPhone = FriendPhone[1];
            }
            FriendPhone = FriendPhone.replace(/[^0-9]+/g, '');
            chattime = chattime[0];
            chattime = chattime.substring(1);
    
            // chattime = chattime.replace(/(\s*$)/g, "");
            // chattime = chattime.substring(0, chattime.length - 1);
            chattime = chattime.split(",");
            chattime = chattime.reverse();
            chattime = chattime.join(",");
            chattime = chattime.replace(/(^\s+)|(\s+$)/g, "");
            // 判断月份和日期是否为两位数
            var newStr = "";
            if (chattime.indexOf('年') != -1) {
                var substrY = chattime.slice(0, 4);
                var substrM = chattime.match(/年(\S*)月/);
                var substrD = chattime.match(/月(\S*)日/);
                var substrH = chattime.split(",")[1];
                var substr1 = substrM[1];
                var substr2 = substrD[1];
            }else{
                var ss = chattime.split(",");
                var ss1 = ss[0];
                var substrY = ss1.substr(ss1.length-4);
                var substrM = chattime.split("/");
                var substrH = chattime.split(",")[1];
                var substr1 = substrM[0];
                var substr2 = substrM[1];
            }
            if (substr1 < 10) {
                var substr1 = "0" + substr1;
            };
    
            if (substr2 < 10) {
                var substr2 = "0" + substr2;
    
            };
            newStr = substrY + "年" + substr1 + "月" + substr2 + "日," + substrH;
            // 判断时间格式中是否含有am或pm
            if (newStr.indexOf("m") != -1) {
                var insertStr = newStr.substr(newStr.length - 2);
                var reg = /,/g;
                newStr = newStr.replace(reg, "," + insertStr);
                newStr = newStr.substring(0, newStr.length - 2);
            }
            arrtimes.push(newStr);
        }
    }
    if(FriendPhone =='' || FriendPhone == null){
        FriendPhone = $("#friend_phone").val();
    }
    arrtimes = arrtimes.splice(-10, 10);
    // console.log(arrtimes)

    // 3、将聊天接收语内容和事件封装成数组对象
    var datas = [];
    for (var i = 0; i < arrChat.length; i++) {
        var obj = {};
        obj.type = 2;
        obj.content = arrChat[i];
        obj.time = arrtimes[i];
        datas.push(obj);
    }


    // 二、聊天记录中回复的信息内容
    // 1、获取对应好友的聊天记录接收内容
    var backChat = $(".message-out span.invisible-space");
    var arrbackChat = [];
    for (var i = 0; i < backChat.length; i++) {
        var backChatOne = backChat[i].innerText;
        arrbackChat.push(backChatOne);
    }
    arrbackChat = arrbackChat.splice(-2, 2);
    // console.log(arrbackChat);

    // 2、获取聊天记录接收的时间与账号名
    var Backchattimes = $(".message-out div.copyable-text");
    var Backarrtimes = [];
    var RegistPhone = "";
    for (var i = 0; i < Backchattimes.length; i++) {
        var Backchattime = Backchattimes[i].getAttribute("data-pre-plain-text");
        if (Backchattime != "" && Backchattime != null) {
            Backchattime = Backchattime.split("]");
            // ① 获取注册账户对应的手机号
            RegistPhone = Backchattime[1];
            RegistPhone = RegistPhone.substring(4);
            RegistPhone = RegistPhone.substring(0, RegistPhone.length - 2);
            RegistPhone = RegistPhone.replace(/\s/g, "");
            // ②  获取时间
            Backchattime = Backchattime[0];
            Backchattime = Backchattime.substring(1);
            // console.log(Backchattime)
            // Backchattime = Backchattime.replace(/(\s*$)/g, "");
            // Backchattime = Backchattime.substring(0, Backchattime.length - 1);
            Backchattime = Backchattime.split(",");
            Backchattime = Backchattime.reverse();
            Backchattime = Backchattime.join(",");
            Backchattime = Backchattime.replace(/(^\s+)|(\s+$)/g, "");

            // 判断月份和日期是否为两位数
            var newStr2 = "";
            
            if (Backchattime.indexOf('年') != -1) {
                var substrYs = Backchattime.slice(0, 4);
                var substrMs = Backchattime.match(/年(\S*)月/);
                var substrDs = Backchattime.match(/月(\S*)日/);
                var substrHs = Backchattime.split(",")[1];
                var substr3 = substrMs[1];
                var substr4 = substrDs[1]
            }else{
                var ss = Backchattime.split(",");
                var ss1 = ss[0];
                var substrYs = ss1.substr(ss1.length-4);
                var substrMs = Backchattime.split("/");
                var substrHs = Backchattime.split(",")[1];
                var substr3 = substrMs[0];
                var substr4 = substrMs[1];
            }
           
            if (substr3 < 10) {
                var substr3 = "0" + substr3;
            };

            if (substr4 < 10) {
                var substr4 = "0" + substr4;

            };
            newStr2 = substrYs + "年" + substr3 + "月" + substr4 + "日," + substrHs;

            // 判断时间格式中是否含有am或pm
            if (newStr2.indexOf("m") != -1) {
                var insertStr = newStr2.substr(newStr2.length - 2);
                var reg = /,/g;
                newStr2 = newStr2.replace(reg, "," + insertStr);
                newStr2 = newStr2.substring(0, newStr2.length - 2);
            }
            Backarrtimes.push(newStr2)
        }
        

    }
    Backarrtimes = Backarrtimes.splice(-2, 2);
    arrObj.push(RegistPhone);
    // 3、 将聊天回复语内容和事件封装成数组对象
    for (var i = 0; i < arrbackChat.length; i++) {
        var BackObj = {};
        BackObj.type = 1;
        BackObj.content = arrbackChat[i];
        BackObj.time = Backarrtimes[i];
        datas.push(BackObj);
    }
    arrObj.push(datas);
    arrObj.push(FriendPhone);
    return arrObj;
    // console.log(datas)
}

// 点击好友获取对应好友的连天记录
function ChangeFriend() {
    var FriendList = $("._2wP_Y");
    FriendList.off('click').on("click", function() {
        var friend_li = $(this).find("._25Ooe"); //.chat-title
        var friend_phone = friend_li.text();
        if (friend_phone.indexOf('+') != -1) {
            friend_phone = friend_phone.split("+");
            friend_phone = friend_phone[1];
        }
        friend_phone = friend_phone.replace(/[^0-9]+/g, '');
       
        var p_html = "<input id='friend_phone'class='friend_phone'  type='hidden' value='"+friend_phone+"'/>";
        if (!$('#friend_phone').hasClass('friend_phone')) {
            $("body").append(p_html);
        } else {
            $("#friend_phone").val(friend_phone);
        }
        var respon = ChatHistory();
        var account = respon[0];
        GetKeyDown(friend_phone);
        $("#container").empty();
        if ($("#container").length != 0) {
            friendTagList(account, friend_phone);
            clickAddTag(account, friend_phone);
        }
        // 把手机号添加到订单查询页面的输入框中
        $(".phone_num").val(friend_phone);
        $(".phone_num2").val(friend_phone);

        // 把手机号添加到创建订单页面的业务员账号输入框中
        var phone = $("#phone").val();
        if(phone!=null && phone !=''){
            $("#accout_id").val(phone);
        }else{
            $("#accout_id").val('');
        }
        // 每次点击输入订单号清空上一次订单列表
        $("#table_order").empty();
        // ajax获取订单列表页面数据
        var _display =$("#order_page").css('display');
        if (_display != 'none') {
            GetOrderList(friend_phone);
        }
        // 每次点击输入订单号清空上一次订单详情
        $("#order_detail").empty();
    })
}

// 回复框点击回车事件
function GetKeyDown(friend_phone) {
    // 获取回复框节点
    var inputText = $("._2S1VP");
    inputText.keydown(function(e) {
        if (e.keyCode == 13) {
            // 点击回复框并调用提交历史记录的方法
            var res = ChatHistory();
            var user_tel = res[0];
            var content_data = res[1];
            // console.log(friend_phone)
            // console.log(user_tel)

            // 获取当前输入的内容和当前时间
            var obj = {};
            var cont = inputText.text();
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var h = date.getHours();
            var mT = date.getMinutes()
            var c = date.getSeconds();
            if (m < 10) {
                m = "0" + m;
            }
            if (d < 10) {
                d = "0" + d;
            }
            if (h < 10) {
                h = "0" + h;
            }
            if (mT < 10) {
                mT = "0" + mT;
            }
            if (c < 10) {
                c = "0" + c;
            }
            var times = y + "-" + m + "-" + d + " " + h + ":" + mT + ":" + c
            obj.content = cont;
            obj.time = times;
            obj.type = 1;
            content_data.push(obj)
                // console.log(content);
                // console.log(content_data)
            PushChatHistory(user_tel, friend_phone, content_data);
        } else {
            // console.log(e.keyCode)
        }
    })
}

// 回复框点击回车事件
function GetKeyDown2(friend_phone,id) {
    // 获取回复框节点
    var inputText = $("._2S1VP");
    // 点击回复框并调用提交历史记录的方法
    var res = ChatHistory();
    var user_tel = res[0];
    var content_data = res[1];
    // console.log(friend_phone)
    // console.log(user_tel)
    if(id==1){
        // 获取当前输入的内容和当前时间
        var obj = {};
        var cont = inputText.text();
        var date = new Date();
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        var h = date.getHours();
        var mT = date.getMinutes()
        var c = date.getSeconds();
        if (m < 10) {
            m = "0" + m;
        }
        if (d < 10) {
            d = "0" + d;
        }
        if (h < 10) {
            h = "0" + h;
        }
        if (mT < 10) {
            mT = "0" + mT;
        }
        if (c < 10) {
            c = "0" + c;
        }
        var times = y + "-" + m + "-" + d + " " + h + ":" + mT + ":" + c
        obj.content = cont;
        obj.time = times;
        obj.type = 1;
        content_data.push(obj)
    }
        // console.log(content);
        // console.log(content_data)
    PushChatHistory(user_tel, friend_phone, content_data);
}

// 通过ajax提交历史记录到后台
function PushChatHistory(user_tel, friend_phone, content_data) {
    if(friend_phone==null || friend_phone==''){
        friend_phone = $("#friend_phone").val();
    }
    if(user_tel==null || user_tel==''){
        user_tel = $("#phone").val();
    }
    if (user_tel != undefined && friend_phone != undefined && content_data != undefined) {
        $.ajax({
            type: "POST",
            dataType: "json",
            cache: false,
            url: "https://www.lampblog.net/phpextjs/web/Home/Api/msgHistoryAdd",
            data: JSON.stringify({
                "token": "7a3bd68cfe8432b738bedf2aedc4e5f5",
                "account": user_tel,
                "friend_phone": friend_phone,
                "content_data": content_data
            }),
            success: function(result) {
                //alert("请求成功");
                // console.log(result)
            },
            error: function() {
                // alert("请求失败");
            }
        })
    }


}



// 鼠标点击回复框后面的发送按钮同步提交聊天历史记录到后台
function PushHistory(){
        var PushChat = $("._2lkdt");
        // console.log(PushChat);
        PushChat.on("click", function() {
            var resp = ChatHistory();
            var user_tel = resp[0];
            var content_data = resp[1];
            var friend_phone = resp[2];
            if(friend_phone==null || friend_phone == ''){
                 friend_phone = $("#friend_phone").val();
            }
            // 获取当前输入的内容和当前时间
            var inputTet = $("._2S1VP");
            var obj = {};
            var cont = inputTet.text();
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var h = date.getHours();
            var mT = date.getMinutes();
            var c = date.getSeconds();
            if (m < 10) {
                m = "0" + m;
            }
            if (d < 10) {
                d = "0" + d;
            }
            if (h < 10) {
                h = "0" + h;
            }
            if (mT < 10) {
                mT = "0" + mT;
            }
            if (c < 10) {
                c = "0" + c;
            }
            var times = y + "-" + m + "-" + d + " " + h + ":" + mT + ":" + c
            obj.content = cont;
            obj.time = times;
            obj.type = 1;
            content_data.push(obj)
                // console.log(user_tel)
                // console.log(content_data)
            PushChatHistory(user_tel, friend_phone, content_data)
            
        })
}